package com.ruoyi.patrol.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.patrol.domain.PtLine;
import com.ruoyi.patrol.domain.PtLineGuard;
import com.ruoyi.patrol.domain.PtLineRecordDetail;
import com.ruoyi.patrol.domain.dto.BasicSituationOfTheSystemDto;
import com.ruoyi.patrol.domain.dto.SchoolPoint;
import com.ruoyi.patrol.service.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

import static com.github.pagehelper.page.PageMethod.startPage;

/**
 * @Description: 江北校园安全大屏数据控制层
 * @author: elis
 * @date: 2023.12.06
 */
@RestController
@RequestMapping("/patrol/ls")
public class PtLargeScreenDataController extends BaseController {

    private final  LargeScreenDataService largeScreenDataService;
    private final IPtLineRecordDetailService ptLineRecordDetailService;
    private final IPtLineService ptLineService;
    private final IPtLineGuardService ptLineGuardService;
    private final IPtMonitorService ptMonitorService;
    public PtLargeScreenDataController(LargeScreenDataService largeScreenDataService, IPtLineRecordDetailService ptLineRecordDetailService, IPtLineService iPtLineService, IPtLineGuardService ptLineGuardService, IPtMonitorService ptMonitorService) {
        this.largeScreenDataService = largeScreenDataService;
        this.ptLineRecordDetailService = ptLineRecordDetailService;
        this.ptLineService = iPtLineService;
        this.ptLineGuardService = ptLineGuardService;
        this.ptMonitorService = ptMonitorService;
    }


    /**
     * 查询大屏展示基本信息
     * 包含 校园信息 安保信息 持证信息 工作人员信息等
     * @return
     */
    @PreAuthorize("@ss.hasPermi('patrol:dp:list')")
    @GetMapping("/getTheBasics")
    public AjaxResult getTheBasics() {
        BasicSituationOfTheSystemDto theBasics = largeScreenDataService.getTheBasics();
        return AjaxResult.success(theBasics);
    }

    /**
     * 查询最近3天巡查记录
     * @return
     */
    @PreAuthorize("@ss.hasPermi('patrol:dp:list')")
    @GetMapping("/getLink")
    public AjaxResult getLink() {
        List<Map<String, Object>> link = largeScreenDataService.getLink();
        return AjaxResult.success(link);
    }

    @PreAuthorize("@ss.hasPermi('patrol:dp:list')")
    @GetMapping("/getLinklist")
    public AjaxResult list(PtLineRecordDetail ptLineRecordDetail) {
        List<PtLineRecordDetail> list = ptLineRecordDetailService.selectPtLineRecordDetailList(ptLineRecordDetail);
        return AjaxResult.success(list);
    }

    @PreAuthorize("@ss.hasPermi('patrol:dp:list')")
    @GetMapping("/getSchoolList")
    public AjaxResult getSchoolList(){
        List<SchoolPoint> schoolList = largeScreenDataService.getSchoolList();
        return AjaxResult.success(schoolList);
    }

    @PreAuthorize("@ss.hasPermi('patrol:dp:list')")
    @GetMapping("/getSchoolInfo")
    public AjaxResult getSchoolInfo(String id){
        return AjaxResult.success(largeScreenDataService.getSchoolInfo(Convert.toInt(id)));
    }

    @PreAuthorize("@ss.hasPermi('patrol:dp:list')")
    @GetMapping("/getMonitor")
    public TableDataInfo getMonitor(){
        startPage();
        List<Map<String, Object>> monitor = largeScreenDataService.getMonitor();
        return getDataTable(monitor);
    }
    @PreAuthorize("@ss.hasPermi('patrol:dp:list')")
    @GetMapping("/getStaff")
    public AjaxResult getStaff(Integer id){
        return AjaxResult.success(largeScreenDataService.getStaff(id));
    }

    @PreAuthorize("@ss.hasPermi('patrol:dp:list')")
    @GetMapping("/getGuard")
    public AjaxResult getGuard(Integer id){
        return AjaxResult.success(largeScreenDataService.getGuard(id));
    }

    @PreAuthorize("@ss.hasPermi('patrol:dp:list')")
    @GetMapping("test")
    public void testUpdateMonitor(){
        ptMonitorService.update();
    }

    @PreAuthorize("@ss.hasPermi('patrol:dp:list')")
    @GetMapping("/lineList")
    public TableDataInfo lineList(String schoolId){
        startPage();
        PtLine ptLine = new PtLine();
        ptLine.setSchoolId(Convert.toLong(schoolId));
        ptLine.setLineType(0);
//        ptLine.(Convert.toLong(shcoolId));

        List<PtLine> list = ptLineService.selectPtLineList(ptLine);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('patrol:dp:list')")
    @GetMapping("/lineGuard")
    public TableDataInfo lineGuard(String schoolId) {
        startPage();
        PtLineGuard ptLineGuard = new PtLineGuard();
        ptLineGuard.setSchoolId(Convert.toLong(schoolId));
        List<PtLineGuard> list = ptLineGuardService.selectPtLineGuardListdp(ptLineGuard);
        return getDataTable(list);
    }
}
